<?php  
	include('../common.php'); 
	$trn_id = "";
	if(!isset($_GET['trn_id'])){
	?>
	<script>
		window.close();
	</script>
	<?php
	}else{
		$trn_id =$_GET['trn_id'];
	}
	
?>

<html>
<head></head>
<style type="text/css" media="print, handheld">
</style>
<body style="margin:10px;">
	<br/>
	<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:12px;text-align:center;">
		<tr>
			<td   colspan="10" style="font-weight:bold;" valign="top" ><h3>Passion Logistic Sdb Bhd</h3></td>
		</tr>
		<tr>
			<td   colspan="10" style="font-weight:bold;" valign="top" ><h2>Load Sheet<h2></td>
		</tr>
		<tr>
			<td   colspan="10" style="font-weight:bold;" align="right"><h1>DIRECT DELIVERY</h1></td>
		</tr>
		<?php
			
			$qIn= "SELECT * FROM person_transport_delivering ptd, transport t, person p
					WHERE
					ptd.ptd_trn_id = t.trn_id
					AND ptd.ptd_person_per_id = p.per_id
					AND ptd.ptd_date_assign_driver = DATE_FORMAT(NOW(),'%y-%m-%d') 
					AND t.trn_id = '$trn_id' ";
				$rIn = $db->sql_list($qIn);
			
			$qCount= "SELECT COUNT(*)  FROM transport t , transport_package_delivering tpd , entity s, entity r
							WHERE t.trn_id = tpd.tpd_trn_id
							AND tpd.tpd_sender_ent_id=s.ent_id
							AND tpd.tpd_receiver_ent_id=r.ent_id
							AND tpd.tpd_trn_id='$trn_id'
							AND tpd.tpd_delivered_date = DATE_FORMAT(NOW(),'%y-%m-%d') 
							ORDER BY tpd_modified_date desc, r.ent_add_postcode DESC";
					$total_pages = $db->sql_total($qCount);			
		
		?>
		<tr>
			<td  style="font-weight:bold;" align="right" >Driver : </td>
			<td  style="font-weight:bold;" align="left" >&nbsp;<?php  echo $rIn['per_full_name']; ?></td>
			<td  style="font-weight:bold;" align="right">Lorry No. : </td>
			<td  style="font-weight:bold;" align="left" >&nbsp;<?php  echo $rIn['trn_plate_no']; ?></td>
			<td  style="font-weight:bold;" align="right">Deliver Date : </td>
			<td  style="font-weight:bold;" align="left" >&nbsp;<?php  echo $rIn['ptd_date_assign_driver']; ?></td>
			<td  style="font-weight:bold;" align="right">Total Doc : </td>
			<td  style="font-weight:bold;" align="left" >&nbsp;<?php  echo $total_pages; ?></td>
			<td  style="font-weight:bold;" align="right">Staff : </td>
			<td  style="font-weight:bold;" align="left" >&nbsp;<?php echo $_SESSION['log_name']; ?></td>
		</tr>
	</table>
	<br/>
	<?php  
						
		/* Get TPD. */
		$qList= "SELECT t.*, tpd.*, s.ent_id AS sid ,
											s.ent_short_name AS sname, 
											r.ent_id AS rid, r.ent_short_name AS rname, r.ent_add_postcode AS rpostcode
											FROM transport t , transport_package_delivering tpd , entity s, entity r
												WHERE t.trn_id = tpd.tpd_trn_id
												AND tpd.tpd_sender_ent_id=s.ent_id
												AND tpd.tpd_receiver_ent_id=r.ent_id
												AND tpd.tpd_delivered_date = DATE_FORMAT(NOW(),'%y-%m-%d') 
												AND tpd.tpd_trn_id='$trn_id'
												ORDER BY tpd_modified_date desc, r.ent_add_postcode DESC ";
		$rList = $db->sql_fetch($qList);			

	?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:12px;text-align:left;">
		
		<tr>
			<td  style="font-weight:bold;" >No.</td>
			<td  style="font-weight:bold;" >No. TDN ID</td>
			<td  style="font-weight:bold;" >Type Pallet</td>
			<td  style="font-weight:bold;" >Sender</td>
			<td  style="font-weight:bold;" >DO Ref.</td>
			<td  style="font-weight:bold;" >Receiver</td>
			<td  style="font-weight:bold;" >Destination</td>
			<td  style="font-weight:bold;" >UOM</td>
			<td  style="font-weight:bold;" >QTY</td>
		</tr>
		<?php
			$num =0;
			foreach ($rList as $i) {
				$num++;
				$colorRow = "first";
				if($num%2==0)
					$colorRow = "second"; 
				else
					$colorRow = "first";
				
				$qCity= "SELECT * from lookup_postcode where postcode = '$i[rpostcode]' ";
				$rCity = $db->sql_list($qCity);
				
				echo '	
					<tr class="'.$colorRow.'">
						<td>'.$num.'</td>
						<td>'.$i['tpd_tdn_no'].'</td>
						<td>'.$i['tpd_type_pallet'].'</td>
						<td>'.$i['sname'].'</td>
						<td>'.$i['tpd_do_ref'].'</td>
						<td>'.$i['rname'].'</td>
						<td>'.$i['rpostcode'].' '.$rCity['post_office'].'</td>
						<td>'.$i['tpd_qty_type'].'</td>
						<td>'.$i['tpd_qty'].'</td>
					</tr>';
				
			}
		?>
		<?php
			if($total_pages == 0){
				echo '	
						<tr>
							<td colspan="9" align="center"  >No Record Found</td>
						</tr>';
			}
		?>
	</table>
	<br/>
	<h4>No. of Record(s) Selected : <?php  echo $total_pages; ?></h4>
	
	
	
</body>
</html>